const fs = require('fs');

function getEntryObj(mod_name = null) {
    var modContent = __dirname + '/mod/';
    var files = fs.readdirSync(modContent);
    var mods = [];//存放所有符合要求的文件名
    var entry = {};//返回webpack 的 入口对象
    var html_config = [];
    if (mod_name) {
        mods = files.filter(fileName => {
            return fileName.startsWith(mod_name)
        })
    } else {
        mods = files;
    }

    mods.forEach(fileName => {
        var key = fileName.split('.')[0];
        entry[key] = modContent + fileName;
        let chunks = [];
        chunks.push(key);
        html_config.push({
            filename: key + '.html',
            title: key,
            chunks,
        })
    })

    return {
        entry,
        html_config
    } 
}

module.exports = getEntryObj